package awt;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @description:
 * @author: Tom
 * @create: 2019-07-23 16:17
 **/
public class TestCardLayout implements ActionListener {

    private Panel p1, p2, p3;
    private Button b1, b2, b3;
    private Frame f;
    private CardLayout cardLayout = new CardLayout();

    public void create() {
        b1=new Button("frist ");
        b2=new Button("second");
        b3=new Button("third");
        p1=new Panel();
        p2=new Panel();
        p3=new Panel();
        f=new Frame("Test CardLayout");
        p1.add(b1);
        b1.addActionListener(this);

        p2.add(b2);
        b2.addActionListener(this);

        p3.add(b3);
        b3.addActionListener(this);

        f.setLayout(cardLayout);

        f.add(p1, "第一层");
        f.add(p2, "第二层");
        f.add(p3, "第三层");
        f.setSize(800, 400);
        f.setVisible(true);

    }

    public static void main(String[] args) {
        TestCardLayout testCardLayout = new TestCardLayout();
        testCardLayout.create();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println(e.getActionCommand());
        cardLayout.next(f);

    }
}
